package com.rs2hd.packethandler;

import com.rs2hd.model.Player;
import com.rs2hd.model.World;
import com.rs2hd.model.Trade;
import com.rs2hd.net.Packet;
import com.rs2hd.net.Packet.Size;
import com.rs2hd.packetbuilder.StaticPacketBuilder;
import com.rs2hd.util.Misc;
import com.rs2hd.util.log.Logger;
import com.rs2hd.model.Skills;
import org.apache.mina.common.IoSession;
import com.rs2hd.GameEngine;
/**
 * Action button handler.
 *
 * @author Graham
 */
public class ActionButtonPacketHandler implements PacketHandler {
public Trade t;
	public int combatDelay = 0;

	private Logger logger = Logger.getInstance();

	@Override
	public void handlePacket(Player player, IoSession session, Packet packet) {
		Player p = player;
		int interfaceId = packet.readShort() & 0xFFFF;
		int buttonId = packet.readShort() & 0xFFFF;
		int buttonId2 = 0;
		if (packet.getLength() >= 6) {
			buttonId2 = packet.readShort() & 0xFFFF;
		}
		if (buttonId2 == 65535) {
			buttonId2 = 0;
		}
		switch (interfaceId) {
		case 430:
			if(buttonId == 36) {
				if (!player.usingVeng) {
					if (player.vengDelay > 0) {
						player.getActionSender().sendMessage("You can only use vengeance 30 seconds after its activated.");
						player.getActionSender().sendMessage("Exceptions for vengeance fades away.");
						return;
					}
					player.graphics(726, (100 << 16));
					player.animate(4410, 0);
					player.usingVeng = true;
					player.vengUseDelay = 60; //30 seconds.
				} else {
					player.getActionSender().sendMessage("You can only cast vengeance every 30 seconds");
				}
			}
			break;
			
			
        case 335:
			if (buttonId == 16){//accept
				p.tAccept[0] = true;
				t.accept(p);
				//Engine.playerTrade.checkStage(p);
			}
			if (buttonId == 18){//decline
				t.close();
				if (p.getRequests().isTrading()) {
                    p.getRequests().closeTrade();
                }
			}
		break;
		case 334:
			if (buttonId == 20){//accept
				p.tAccept[1] = true;
				//Engine.playerTrade.checkStage(p);
				t.accept(p);
			}
			if (buttonId == 21){//decline
				t.close();
				if (p.getRequests().isTrading()) {
                    p.getRequests().closeTrade();
                }
			}
		break;


       case 583:
           if (buttonId == 50) {
               if (player.PkPoints >= 125) {
                   player.getInventory().addItem(14484, 1);
                   player.PkPoints -= 50;
               } else {
		           player.getActionSender().sendMessage("You Need 125 Shop Points To Buy Dragon Claws");
               }
           }
           if (buttonId == 51) {
               if (player.PkPoints >= 200) {
                   player.getInventory().addItem(15241, 1);
                   player.PkPoints -= 200;
               } else {
		           player.getActionSender().sendMessage("You Need 200 Shop Points To Buy Hand Cannon");
               }
           }
           if (buttonId == 52) {
               if (player.PkPoints >= 50) {
                   player.getInventory().addItem(13887, 1);
                   player.PkPoints -= 50;
               } else {
		           player.getActionSender().sendMessage("You Need 50 Shop Points To Buy Vesta Chain");
               }
           }
           if (buttonId == 53) {
               if (player.PkPoints >= 50) {
                   player.getInventory().addItem(13893, 1);
                   player.PkPoints -= 50;
               } else {
		           player.getActionSender().sendMessage("You Need 50 Shop Points To Buy Vesta Skirt");
               }
           }
           if (buttonId == 54) {
               if (player.PkPoints >= 50) {
                   player.getInventory().addItem(13899, 1);
                   player.PkPoints -= 50;
               } else {
		           player.getActionSender().sendMessage("You Need 50 Shop Points To Buy Vesta LongSword");
               }
           }
           if (buttonId == 55) {
               if (player.PkPoints >= 50) {
                   player.getInventory().addItem(13896, 1);
                   player.PkPoints -= 50;
               } else {
		           player.getActionSender().sendMessage("You Need 50 Shop Points To Buy Statius Helm");
               }
           }
           if (buttonId == 56) {
               if (player.PkPoints >= 50) {
                   player.getInventory().addItem(13890, 1);
                   player.PkPoints -= 50;
               } else {
		           player.getActionSender().sendMessage("You Need 50 Shop Points To Buy Statius Legs");
               }
           }
           if (buttonId == 57) {
               if (player.PkPoints >= 50) {
                   player.getInventory().addItem(13884, 1);
                   player.PkPoints -= 50;
               } else {
		           player.getActionSender().sendMessage("You Need 50 Shop Points To Buy Statius Plate");
               }
           }
           if (buttonId == 58) {
               if (player.PkPoints >= 80) {
                   player.getInventory().addItem(4753, 1);
                   player.getInventory().addItem(4755, 1);
                   player.getInventory().addItem(4757, 1);
                   player.getInventory().addItem(4759, 1);
                   player.PkPoints -= 80;
               } else {
		           player.getActionSender().sendMessage("You Need 80 Shop Points To Buy Veracs Set");
               }
           }
           if (buttonId == 59) {
               if (player.PkPoints >= 80) {
                   player.getInventory().addItem(4745, 1);
                   player.getInventory().addItem(4747, 1);
                   player.getInventory().addItem(4749, 1);
                   player.getInventory().addItem(4751, 1);
                   player.PkPoints -= 80;
               } else {
		           player.getActionSender().sendMessage("You Need 80 Shop Points To Buy Torags Set");
               }
           }
           if (buttonId == 71) {
               if (player.PkPoints >= 80) {
                   player.getInventory().addItem(4712, 1);
                   player.getInventory().addItem(4714, 1);
                   player.getInventory().addItem(4710, 1);
                   player.getInventory().addItem(4708, 1);
                   player.PkPoints -= 80;
               } else {
		           player.getActionSender().sendMessage("You Need 80 Shop Points To Buy Ahrims Set");
               }
           }
           if (buttonId == 60) {
               if (player.PkPoints >= 80) {
                   player.getInventory().addItem(4730, 1);
                   player.getInventory().addItem(4728, 1);
                   player.getInventory().addItem(4726, 1);
                   player.getInventory().addItem(4724, 1);
                   player.PkPoints -= 80;
               } else {
		           player.getActionSender().sendMessage("You Need 80 Shop Points To Buy Guthans Set");
               }
           }
           if (buttonId == 61) {
               if (player.PkPoints >= 80) {
                   player.getInventory().addItem(4716, 1);
                   player.getInventory().addItem(4718, 1);
                   player.getInventory().addItem(4720, 1);
                   player.getInventory().addItem(4722, 1);
                   player.PkPoints -= 80;
               } else {
		           player.getActionSender().sendMessage("You Need 80 Shop Points To Buy Dharoks Set");
               }
           }
           if (buttonId == 62) {
               if (player.PkPoints >= 5) {
                   player.getInventory().addItem(6585, 1);
                   player.PkPoints -= 5;
               } else {
		           player.getActionSender().sendMessage("You Need 5 Shop Points To Buy Amulet Of Fury");
               }
           }
           if (buttonId == 64) {
               if (player.PkPoints >= 60) {
                   player.getInventory().addItem(11694, 1);
                   player.PkPoints -= 60;
               } else {
		           player.getActionSender().sendMessage("You Need 60 Shop Points To Buy Armadyl GS");
               }
           }
           if (buttonId == 63) {
               if (player.PkPoints >= 55) {
                   player.getInventory().addItem(11698, 1);
                   player.PkPoints -= 55;
               } else {
		           player.getActionSender().sendMessage("You Need 55 Shop Points To Buy Saradomin GS");
               }
           }
           if (buttonId == 65) {
               if (player.PkPoints >= 50) {
                   player.getInventory().addItem(11696, 1);
                   player.PkPoints -= 50;
               } else {
		           player.getActionSender().sendMessage("You Need 50 Shop Points To Buy Bandos GS");
               }
           }
           if (buttonId == 70) {
               if (player.PkPoints >= 45) {
                   player.getInventory().addItem(11700, 1);
                   player.PkPoints -= 45;
               } else {
		           player.getActionSender().sendMessage("You Need 45 Shop Points To Buy Zamorak GS");
               }
           }
           if (buttonId == 66) {
               if (player.PkPoints >= 15) {
                   player.getInventory().addItem(4151, 1);
                   player.PkPoints -= 15;
               } else {
		           player.getActionSender().sendMessage("You Need 15 Shop Points To Buy Whip");
               }
           }
           if (buttonId == 67) {
               if (player.PkPoints >= 15) {
                   player.getInventory().addItem(6889, 1);
                   player.PkPoints -= 15;
               } else {
		           player.getActionSender().sendMessage("You Need 15 Shop Points To Buy Mage Book");
             }
           }
           if (buttonId == 68) {
               if (player.PkPoints >= 20) {
                   player.getInventory().addItem(8013, 10);
                   player.PkPoints -= 20;
               } else {
		           player.getActionSender().sendMessage("You Need 20 Shop Points To Buy X10 Home Teletabs");
             }
           }
           if (buttonId == 69) {
               if (player.PkPoints >= 150) {
                   player.getInventory().addItem(6570, 1);
                   player.PkPoints -= 150;
                 } else {
		           player.getActionSender().sendMessage("You Need 150 Shop Points To Buy Firecape");
               }
           }
           if (buttonId == 73) {
               if (player.PkPoints >= 63) {
                   player.getInventory().addItem(11283, 1);
                   player.PkPoints -= 63;
               } else {
		           player.getActionSender().sendMessage("You Need 63 Shop Points To Buy DragonFire Shield");
               }
           }
           if (buttonId == 72) {
               if (player.PkPoints >= 40) {
                   player.getInventory().addItem(9748, 1);
                   player.getInventory().addItem(9751, 1);
                   player.getInventory().addItem(9754, 1);
                   player.getInventory().addItem(9757, 1);
                   player.getInventory().addItem(9760, 1);
                   player.getInventory().addItem(9763, 1);
                   player.getInventory().addItem(9766, 1);
                   player.getInventory().addItem(9769, 1);
                   player.getInventory().addItem(9772, 1);
                   player.getInventory().addItem(9775, 1);
                   player.getInventory().addItem(9778, 1);
                   player.getInventory().addItem(9781, 1);
                   player.getInventory().addItem(9784, 1);
                   player.getInventory().addItem(9787, 1);
                   player.getInventory().addItem(9790, 1);
                   player.getInventory().addItem(9793, 1);
                   player.getInventory().addItem(9796, 1);
                   player.getInventory().addItem(9799, 1);
                   player.getInventory().addItem(9802, 1);
                   player.getInventory().addItem(9805, 1);
                   player.getInventory().addItem(9808, 1);
                   player.getInventory().addItem(9811, 1);
                   player.getInventory().addItem(12170, 1);
                   player.PkPoints -= 40;
               } else {
		           player.getActionSender().sendMessage("You Need 40 Shop Points To Buy Firecape");
              }
           }
           break;

  case 192:
        if (buttonId == 40) {//varrock
       player.tele(3212 ,3428 , 0);
    player.getActionSender().sendMessage("You Teleported to varrock.");
   }
        if (buttonId == 43) {//lumbridge 
       player.tele(3221 ,3219 , 0);
    player.getActionSender().sendMessage("You Teleported to lumbridge.");
   }
        if (buttonId == 46) {//falador
       player.tele(2964 ,3380 , 0);
    player.getActionSender().sendMessage("You Teleported to falador.");
   }
        if (buttonId == 51) {//camelot
player.tele(2757 ,3487 , 0);
    player.getActionSender().sendMessage("You Teleported to camelot.");
   }
        if (buttonId == 57) {//ardougne
player.tele(2662 ,3308 , 0);
    player.getActionSender().sendMessage("You Teleported to ardougne.");
   }
  break;



		case 749:
			System.out.println(packet.getId());
			if (packet.getId() == 216) {
				GameEngine.prayer.handlePrayerSwitch(player, 1);
			}
			if (packet.getId() == 19) {
				GameEngine.prayer.handlePrayerSwitch(player, 2);
			}
			break;
		case 271:
			if (buttonId == 8) {
				GameEngine.prayer.handlePrayerSwitch(player, 2);
			}
			if (buttonId == 7) {
				GameEngine.prayer.QuickhandlePrayerUse(player, buttonId2);
			}
			if (buttonId == 6) {
				GameEngine.prayer.handlePrayerUse(player, buttonId2);
			}
			break;
		case 300:
			player.getSmithing().handlebuttons(player, interfaceId, buttonId, buttonId2);
			break;
		case 387:
			/*
			 * Equipment tab.
			 */
			switch (buttonId) {
			case 56: // Equipment Screen
				player.getActionSender().sendInterface(667);
				player.getBonuses().refresh();
				player.setEquipmentBonus();
				player.getActionSender().sendAccessMask(1030, 667, 14, 0, 13);
				break;
			case 63: // Price Checker
				player.getActionSender().sendInterface(206);
				break;
			case 53: // IKOD - Items Kept On Death
				player.getActionSender().sendInterface(102);
				break;
			default:
				System.out.println("Unhandled button id: 387, " + buttonId + ".");
			break;
			}
			break; 
		case 259:
			if(buttonId == 2) {
				for (int i = 0; i < Skills.SKILL_COUNT; i++) {
					player.getSkills().addXp(i, 14000000);
				}
			}
			break;
		case 750: //Running Button.
			if(buttonId == 1) {
				if(!player.getWalkingQueue().isRunToggled()) {
					player.getWalkingQueue().setRunToggled(true);
					player.getActionSender().sendConfig(173, 1);
				} else {
					player.getWalkingQueue().setRunToggled(false);
					player.getActionSender().sendConfig(173, 0);
				}
			}
			break;
		case 884:
			switch (buttonId) {
			case 11:
				player.setAttackStyle(0);
				break;
			case 12:
				player.setAttackStyle(1);
				break;
			case 13:
				player.setAttackStyle(2);
				break;
			case 14:
				player.setAttackStyle(3);
				break;
			case 15:
				//Auto ret
				break;
			}
			if (buttonId >= 11 && buttonId <= 14) {
				player.getActionSender().sendConfig(43, player.getAttackStyle());
			}
			if(buttonId == 4) {//Specials
				boolean active = player.getCombat().useSpec;
				if (active) {
					player.getActionSender().sendConfig(301, 0);
					player.setSpecial(false);
				} else {
					player.getActionSender().sendConfig(301, 1);
					player.setSpecial(true);
					return;
				}
				if (p.getCombat().attacking) {
					if (p.wearingGMAUL() && p.getCombat().specialAmount >= 500) {
						final Player opp = World.getInstance().getPlayerList().get(p.getCombat().enemyIndex);
						if (opp == null) {
							return;
						}
						if (opp.isDead()) {
							return;
						}
		                                if (p.getCombat().inCombatWith != opp.getIndex() && p.getCombat().inCombatWith != 0) {	
		                                  if (opp.NormalZone()) {			
			                                p.getActionSender().sendMessage("You are already in combat.");	
							p.getCombat().attacking = false;
							p.following = false;
			                                return;
                                                   }
                                                }
		                                if (opp.getCombat().inCombatWith != p.getIndex() && opp.getCombat().inCombatWith != 0 ) {
		                                   if (p.NormalZone()) {				
			                                p.getActionSender().sendMessage("That player is already in combat.");	
							p.getCombat().attacking = false;
							p.following = false;
			                                return;
                                                   }
                                                }
						if (p.SafeZone()) {
							p.getActionSender().sendMessage("You are not in a PvP area to be allowed to attack!");
							p.getCombat().attacking = false;
							p.following = false;
							return;
						}
						if (opp.SafeZone()) {
							p.getActionSender().sendMessage("This player is not in a PvP area to be attacked!");
							p.getCombat().attacking = false;
							p.following = false;
							return;
						}
						p.getCombat().inCombatWith = opp.getIndex();
						p.getCombat().combatWithTime = 8;
						opp.getCombat().inCombatWith = p.getIndex();
						opp.getCombat().combatWithTime = 8;
						p.getCombat().specialAmount -= 500;
						p.getCombat().refreshSpecial();
						player.getActionSender().sendConfig(301, 0);
						player.setSpecial(false);
						p.animate(1667, 0);
						p.graphics(340, 0);
						p.getCombat().combatDelay = 7;
						int hitDamage = Misc.random(player.MaxHitSpec());
						int hitDamage2 = Misc.random(player.MaxHitSpec());
						opp.hit(hitDamage);
						opp.hit(hitDamage2);
						return;
					} else if (p.wearingGMAUL() && p.getCombat().specialAmount <= 499) {
						p.getActionSender().sendMessage("You don't have enough special energy.");
						player.getActionSender().sendConfig(301, 0);
						player.setSpecial(false);
						return;
					}
				}
			}
			break;
		case 261: // Settings tab
			if(buttonId == 16) {
				player.getActionSender().sendInterface(742);
			}
			if(buttonId == 18) {
				player.getActionSender().sendInterface(743);
			}
			if(buttonId == 1) {
player.getBank().openBank();
			}
			if(buttonId == 2) {
player.getBank().openBank();
			}
			if(buttonId == 8) {
player.getBank().openBank();
			}
			if(buttonId == 3) {
				if(!player.getWalkingQueue().isRunToggled()) {
					//player.getWalkingQueue().setRunToggled(true);
					player.getActionSender().sendConfig(173, 1);
					player.getActionSender().sendMessage("Running not avaiable yet.");
				} else {
					//player.getWalkingQueue().setRunToggled(false);
					player.getActionSender().sendConfig(173, 0);
				}
			}
			if(buttonId == 4) {
				if(!player.getSettings().isChatEffectsEnabled()) {
					player.getSettings().setChatEffectsEnabled(true);
					player.getActionSender().sendConfig(171, 0);
				} else {
					player.getSettings().setChatEffectsEnabled(false);
					player.getActionSender().sendConfig(171, 1);
				}
			}
			if(buttonId == 5) {
				if(!player.getSettings().isPrivateChatSplit()) {
					StaticPacketBuilder spb = new StaticPacketBuilder().setId(70).setSize(Size.VAR_SHORT)
					.addShort(0)
					.addString("")
					.addInt(83);
					player.getSession().write(spb.toPacket());
					player.getSettings().setPrivateChatSplit(true);
					player.getActionSender().sendConfig(287, 1);
				} else {
					player.getSettings().setPrivateChatSplit(false);
					player.getActionSender().sendConfig(287, 0);
				}
				break;			
			}
			if(buttonId == 7) {
                                player.shop(player);
			}
			if(buttonId == 6) {
				if(!player.getSettings().isMouseTwoButtons()) {
					player.getSettings().setMouseTwoButtons(true);
					player.getActionSender().sendConfig(170, 0);
				} else {
					player.getSettings().setMouseTwoButtons(false);
					player.getActionSender().sendConfig(170, 1);
				}
			}
			if (buttonId == 16) {
				player.getActionSender().sendInterface(742);
			}
			if (buttonId == 18) {
				player.getActionSender().sendInterface(743);
			}
			break;

		case 182:
			/*
			 * Logout.
			 */
			player.getActionSender().sendLogout();
			break;
		case 746:
		case 548:
			switch (buttonId) {
			case 67:
				/*
				 * Show world map.
				 */
				// TODO make it work well
				player.getActionSender().sendWindowPane(755, 0);
				break;
			}
			break;
		case 755:
			switch (buttonId) {
			case 9:
				/*
				 * Close world map.
				 */
				// TODO make it work well.
				// player.getActionSender().sendWindowPane(548);
				// player.getSession().write(new StaticPacketBuilder().setId(173).toPacket());
				break;
			default:
				logger.debug("Unhandled button id: 755, " + buttonId + ".");
			break;
			}
			break;
		case 464:
			/*
			 * Emote tab.
			 */
			if (buttonId == 2) {
				player.animate(855, 0);
			} else if (buttonId == 3) {
				player.animate(856, 0);
			} else if (buttonId == 4) {
				player.animate(858, 0);
			} else if (buttonId == 5) {
				player.animate(859, 0);
			} else if (buttonId == 6) {
				player.animate(857, 0);
			} else if (buttonId == 7) {
				player.animate(863, 0);
			} else if (buttonId == 8) {
				player.animate(2113, 0);
			} else if (buttonId == 9) {
				player.animate(862, 0);
			} else if (buttonId == 10) {
				player.animate(864, 0);
			} else if (buttonId == 11) {
				player.animate(861, 0);
			} else if (buttonId == 12) {
				player.animate(2109, 0);
			} else if (buttonId == 13) {
				player.animate(2111, 0);
			} else if (buttonId == 14) {
				player.animate(866, 0);
			} else if (buttonId == 15) {
				player.animate(2106, 0);
			} else if (buttonId == 16) {
				player.animate(2107, 0);
			} else if (buttonId == 17) {
				player.animate(2108, 0);
			} else if (buttonId == 18) {
				player.animate(860, 0);
			} else if (buttonId == 19) {
				player.animate(0x558, 0);
				player.graphics(1702, 0);
			} else if (buttonId == 20) {
				player.animate(2105, 0);
			} else if (buttonId == 21) {
				player.animate(2110, 0);
			} else if (buttonId == 22) {
				player.animate(865, 0);
			} else if (buttonId == 23) {
				player.animate(2112, 0);
			} else if (buttonId == 24) {
				player.animate(0x84F, 0);
			} else if (buttonId == 25) {
				player.animate(0x850, 0);
			} else if (buttonId == 26) {
				player.animate(1131, 0);
			} else if (buttonId == 27) {
				player.animate(1130, 0);
			} else if (buttonId == 28) {
				player.animate(1129, 0);
			} else if (buttonId == 29) {
				player.animate(1128, 0);
			} else if (buttonId == 30) {
				player.animate(4275, 0);
			} else if (buttonId == 31) {
				player.animate(1745, 0);
			} else if (buttonId == 32) {
				player.animate(4280, 0);
			} else if (buttonId == 33) {
				player.animate(4276, 0);
				player.graphics(712, 0);
			} else if (buttonId == 34) {
				player.animate(3544, 0);
			} else if (buttonId == 35) {
				player.animate(3543, 0);
			} else if (buttonId == 36) {
				player.animate(7272, 0);
				player.graphics(1244, 0);
			} else if (buttonId == 37) {
				player.animate(2836, 0);
			} else if (buttonId == 38) {
				player.animate(6111, 0);
			} else if (buttonId == 39) {// Skillcape emotes
				if(player.getEquipment().get(1) == null) {
					return;
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9747) {
					player.graphics(823,1);
					player.animate(4959,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9748) {
					player.graphics(823,1);
					player.animate(4959,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9753) { 
					player.graphics(824,1);
					player.animate(4961,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9754) { 
					player.graphics(824,1);
					player.animate(4961,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9750) { 
					player.graphics(828,1);
					player.animate(4981,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9751) { 
					player.graphics(828,1);
					player.animate(4981,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9768) {
					player.graphics(833,1);
					player.animate(4971,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9769) {
					player.graphics(833,1);
					player.animate(4971,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9756) {
					player.graphics(832,1);
					player.animate(4973,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9757) {
					player.graphics(832,1);
					player.animate(4973,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9759) {
					player.graphics(829,1);
					player.animate(4979,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9760) {
					player.graphics(829,1);
					player.animate(4979,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9762) {
					player.graphics(813,1);
					player.animate(4939,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9763) {
					player.graphics(813,1);
					player.animate(4939,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9801) {
					player.graphics(821,1);
					player.animate(4955,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9802) {
					player.graphics(821,1);
					player.animate(4955,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9807) {
					player.graphics(822,1);
					player.animate(4957,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9808) {
					player.graphics(822,1);
					player.animate(4957,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9783) {
					player.graphics(812,1);
					player.animate(4937,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9784) {
					player.graphics(812,1);
					player.animate(4937,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9798) {
					player.graphics(819,1);
					player.animate(4951,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9799) {
					player.graphics(819,1);
					player.animate(4951,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9804) {
					player.graphics(831,1);
					player.animate(4975,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9805) {
					player.graphics(831,1);
					player.animate(4975,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9780) {
					player.graphics(818,1);
					player.animate(4949,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9781) {
					player.graphics(818,1);
					player.animate(4949,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9795) {
					player.graphics(815,1);
					player.animate(4943,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9796) {
					player.graphics(815,1);
					player.animate(4943,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9792) {
					player.graphics(814,1);
					player.animate(4941,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9793) {
					player.graphics(814,1);
					player.animate(4941,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9774) {
					player.graphics(835,1);
					player.animate(4969,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9775) {
					player.graphics(835,1);
					player.animate(4969,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9771) {
					player.graphics(830,1);
					player.animate(4977,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9772) {
					player.graphics(830,1);
					player.animate(4977,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9777) {
					player.graphics(826,1);
					player.animate(4965,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9778) {
					player.graphics(826,1);
					player.animate(4965,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9786) {
					player.graphics(1656,1);
					player.animate(4967,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9787) {
					player.graphics(1656,1);
					player.animate(4967,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9810) {
					player.graphics(825,1);
					player.animate(4963,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9811) {
					player.graphics(825,1);
					player.animate(4963,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9765) {
					player.graphics(817,1);
					player.animate(4947,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9766) {
					player.graphics(817,1);
					player.animate(4947,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9810) {
					player.graphics(825,1);
					player.animate(4963,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9811) {
					player.graphics(825,1);
					player.animate(4963,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9813) {
					player.graphics(816,1);
					player.animate(4945,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9814) {
					player.graphics(816,1);
					player.animate(4945,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9789) {
					player.graphics(820,1);
					player.animate(4953,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9790) {
					player.graphics(820,1);
					player.animate(4953,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9948) {
					player.graphics(907,1);
					player.animate(5158,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 9949) {
					player.graphics(907,1);
					player.animate(5158,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 12169) {
					player.graphics(1515,1);
					player.animate(8525,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 12170) {
					player.graphics(1515,1);
					player.animate(8525,1);
				}
				if (buttonId == 39 && player.getEquipment().get(1).getDefinition().getId() == 10662) {
					player.graphics(816,1);
					player.animate(4945,1);
				}
				else {
					player.getActionSender().sendMessage("You must be wearing a SkillCape to perform this emote.");
				}
			} else if (buttonId == 40) {
				player.animate(7531, 0); 
			} else if (buttonId == 41) {
				player.animate(2414, 0);
				player.graphics(1537, 0);
			} else if (buttonId == 42)  {
				player.animate(8770, 0); 
				player.graphics(1553, 0);
			} else if (buttonId == 43) {
				player.animate(9990, 0);
				player.graphics(1734, 0);
			} else if (buttonId == 44) { 
				player.animate(10530, 0);
				player.graphics(1864, 0);
			} else if (buttonId == 45) { 
				player.animate(11044, 0); 
				player.graphics(1973, 0);  
			} else if (buttonId == 46) {
				player.animate(10996, 0); 
				player.graphics(1714, 0);
			}
			break;
		case 762:
			/*
			 * Bank interface.
			 */
			switch(buttonId) {
			case 81:
				if (packet.getId() == 216) {
					player.getBank().withdrawItem(buttonId2, 1);
				} else if (packet.getId() == 19) {
					player.getBank().withdrawItem(buttonId2, 5);
				} else if (packet.getId() == 193) {
					player.getBank().withdrawItem(buttonId2, 10);
				} else if (packet.getId() == 89) {
					player.getBank().withdrawItem(buttonId2, -100);
				} else if (packet.getId() == 173) {
					player.getInputHandler().requestIntegerInput(player, 1, "Enter amount to withdraw:", buttonId2);
				}
				break;
			}
			break;
		case 763:
			/*
			 * Bank interface.
			 */
			if (buttonId == 0) {
				if (packet.getId() == 216) {
					player.getBank().bankItem(buttonId2, 1);   
				} else if (packet.getId() == 19) {
					player.getBank().bankItem(buttonId2, 5);
				} else if (packet.getId() == 193) {
					player.getBank().bankItem(buttonId2, 10);
				} else if (packet.getId() == 89) {
					player.getBank().bankItem(buttonId2, -100);
				} else if (packet.getId() == 173) {
					player.getInputHandler().requestIntegerInput(player, 2, "Enter amount to deposit:", buttonId2);
				}
			}
			break;
		default:
			System.out.println("Unhandled button id: " + interfaceId + " , " + buttonId + ".");
		break;
		}
	}

}
